package com.malie.myspringboot.rabbitmq;

import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

public class ConnectionUtil {
    /**
     * 建立连接
     */
    public static Connection getConnection() throws Exception {
        // 连接工厂
        ConnectionFactory connectionFactory = new ConnectionFactory();
        // 服务地址
        connectionFactory.setHost("150.158.154.25");
        // 端口
        connectionFactory.setPort(5672);
        //设置账号信息，用户名、密码、vhost
        //  factory.setVirtualHost("/kavito");//设置虚拟机，一个mq服务可以设置多个虚拟机，每个虚拟机就相当于一个独立的mq
        connectionFactory.setUsername("guest");
        connectionFactory.setPassword("guest");
        Connection connection = connectionFactory.newConnection();
        return connection;
    }
}
